//
//  ToolMacroDefine.h
//  OCBase
//
//  Created by Duncan on 2021/1/12.
//

#ifndef ToolMacroDefine_h
#define ToolMacroDefine_h

#define kScreen_Bounds ([[UIScreen mainScreen] bounds])
#define kScreen_Width ([[UIScreen mainScreen] bounds].size.width)
#define kScreen_Height ([[UIScreen mainScreen] bounds].size.height)

// 是否iphone
#define kUserInterPhone ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)

#define iPhoneX [[UIApplication sharedApplication] windows].lastObject.safeAreaInsets.bottom > 0
// 状态栏高度
#define kStatusHeight  UIApplication.sharedApplication.windows.firstObject.safeAreaInsets.top
// 导航栏高度
#define kBarHeight  self.navigationController.navigationBar.bounds.size.height
// 状态栏加导航栏高度
#define kStatusbarAndNavigationbarHeight (iPhoneX ? 88 : 64)
// 顶部安全区域高度
#define kSafearea_top                   (iPhoneX ? 24.0f : 0.0f)
// 底部安全区域高度
#define kSafearea_bottom                (iPhoneX ? 34.0f : 0.0f)

// 文件保存的路径
#define kLOCALDIR [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]


#define kOCNormal_String @"OCNormal"
#define kOCNormalPathString [kLOCALDIR stringByAppendingPathComponent:kOCNormal_String]
#define kOCNormal_Appending(string) [kOCNormalPathString stringByAppendingPathComponent:string]



#define kWEAKSELF __weak typeof(self) weakSelf = self;

#ifdef DEBUG
#define DEBUGLOG(format, ...) NSLog((@ "\n[file:%s]" "\n[function:%s]" "\n[line:%d]\n%@\n"  format), __FILE__, __FUNCTION__, __LINE__, [NSDate getNowTimeFormatStringToMillisecond], ## __VA_ARGS__);
#else
#define DEBUGLOG(...)
#endif

#ifndef dispatch_main_async_safe
#define dispatch_main_async_safe(block)\
    if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {\
        block();\
    } else {\
        dispatch_async(dispatch_get_main_queue(), block);\
    }
#endif

#pragma mark ------- 自定义 -------

#define kMinQxStr(a)    [NSString stringWithFormat:@"%@",a]
#define kIntQxStr(a)    [NSString stringWithFormat:@"%ld",a]
#define kImageName(Name) ([UIImage imageNamed:Name]) // 加载本地图片


// UI
#define kCommonBtnHeight kFragmemtFloat(40)
#define kNavigationBarTitleFont kAdaptedMediumFontSize(17)

// 分页默认列表数
#define kNormalPageSize @20

#define kIsEmpty(_object) (_object == nil \
|| [_object isKindOfClass:[NSNull class]] \
|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \
|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))

#pragma mark ------- 单例模式 -------
//.h头文件中的单例宏
#define kIMSingletonH(name) + (instancetype)shared;

//.m文件中的单例宏
#define kIMSingletonM(name) \
static id _instance;\
+ (instancetype)allocWithZone:(struct _NSZone *)zone{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [super allocWithZone:zone];\
});\
return _instance;\
}\
+ (instancetype)shared{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [[self alloc] init];\
});\
return _instance;\
}\
- (id)copyWithZone:(NSZone *)zone{\
return _instance;\
}



#endif /* ToolMacroDefine_h */
